package cn.tedu.car.backend.vehicleStation.controller;

import cn.tedu.car.backend.base.response.JsonResult;
import cn.tedu.car.backend.base.response.StatusCode;
import cn.tedu.car.backend.vehicleStation.pojo.dto.VehicleQuery;
import cn.tedu.car.backend.vehicleStation.pojo.vo.VehicleVO;
import cn.tedu.car.backend.vehicleStation.service.VehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "车辆服务")
@Slf4j
@RequestMapping("/vehicle")
public class VehicleController1 {
    @Autowired
    private VehicleService vehicleService;

    @PostMapping("/unbindVehicle/{id}")
    public JsonResult unbindVehicle(@PathVariable Long id){
        vehicleService.unbindVehicle(id);
        return JsonResult.ok();
    }
    @GetMapping("getVehicle")
    @ApiOperation("获取可绑定车辆")
    public JsonResult getVehicle(VehicleQuery vehicleQuery){
        log.debug("查询车辆参数:{}",vehicleQuery);
        List<VehicleVO> vehicleVOList = vehicleService.getVehicle(vehicleQuery);
        log.debug("返回车辆列表vehicleVOList：{}",vehicleVOList);
        if (vehicleVOList.isEmpty()){
            return new JsonResult(StatusCode.OPERATION_FAILED);
        }
        return JsonResult.ok(vehicleVOList);
    }
}
